const tree = {
  val: 'a',
  children: [{
    val: 'b',
    children: [{
      val: 'd',
    }, {
      val: 'e',
    }]
  }, {
    val: 'c',
    children: [{
      val: 'f',
    }, {
      val: 'g',
    }]
  }]
}

const bfs = (tree) => { 
  let q = [tree]
  while(q.length > 0){
    const n = q.shift()
    console.log(n.val)
    if(n.children){
      q = q.concat(n.children)
    }
  }
}

bfs(tree)
